package com.hd123.rumba.qt.def;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.hd123.rumba.exception.BusinessException;

public class SQLUnionList extends ArrayList implements List {
  /**
   * 返回适用于union的子句
   * 
   * @return
   */
  public String getSQLClause() throws IOException, ParseException, BusinessException {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < size(); ++i) {
      SQLUnion u = (SQLUnion) get(i);
      if (u.isDistinct())
        sb.append("\n union \n");
      else
        sb.append("\n union all \n");
      sb.append(u.getSQLClause());
    }
    return sb.length() == 0 ? null : sb.toString();
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer();
    sb.append(getClass().getName() + "\n");
    for (int i = 0; i < size(); ++i) {
      SQLUnion item = (SQLUnion) get(i);
      sb.append(i + ": " + item.debugInfo() + "\n");
    }
    return sb.toString();
  }
}
